//
//  DBCalendarWay.m
//  CarCare
//
//  Created by ileo on 15/5/6.
//  Copyright (c) 2015年 baozun. All rights reserved.
//

#import "DBCalendarWay.h"
#import "CalendarMgr.h"

@implementation CalendarWayModel

-(void)setDateString:(NSString *)dateString{
    _dateString = dateString;
    self.orderDate = [[CALENDARMGR dateWithStr:dateString format:@"yyyy-MM-dd"] timeIntervalSince1970];
    self.searchDate = [dateString substringToIndex:7];
}

+(NSString *)primaryKey{
    return @"orderDate";
}

@end

@implementation DBCalendarWay

-(void)dealloc{

}

-(void)createTable{
    self.tableName = @"DBCalendarWay";
    [self.dataBase open];
    if (![self.dataBase tableExists:self.tableName]) {
        NSError *error = nil;
        if ([self.dataBase createTableWithName:self.tableName columns:[CalendarWayModel dbColumns] constraints:@[] error:&error]) {
        }
    }
    [self.dataBase close];
}

-(NSArray *)datasWithSearchDate:(NSString *)searchDate{
    self.where = [NSString stringWithFormat:@"(searchDate = '%@')",searchDate];
    return [super datas];
}

-(void)editDatas:(NSArray *)datas{
    self.where = @"orderDate";
    [super editDatas:datas];
}

@end
